﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PVW;
using System.Runtime.InteropServices;

namespace ReporterSystem
{
    internal class clsProvision
    {
        // Fields
        private IpvwApp m_pvwApp;
        private IpvwAppCIF m_pvwAppCIF;
        private IpvwAppFileManagement m_pvwAppFileManagement;
        private IpvwAppVersion m_pvwAppVersion;
        private PVWorkbenchClass m_pvwServer;

        // Methods
        public void EndProvision()
        {
            this.m_pvwApp = null;
            this.m_pvwAppCIF = null;
            this.m_pvwServer = null;
        }

        public bool IsCIF3()
        {
            return ((this.m_pvwAppVersion.MajorVersion > 6) | ((this.m_pvwAppVersion.MajorVersion == 6) & (this.m_pvwAppVersion.MinorVersion >= 2)));
        }

        public bool StartProvision()
        {
            try
            {
                this.m_pvwServer = new PVWorkbenchClass();
                this.m_pvwApp = this.m_pvwServer;
                this.m_pvwAppCIF = (IpvwAppCIF)this.m_pvwServer;
                this.m_pvwAppFileManagement = (IpvwAppFileManagement)this.m_pvwServer;
                this.m_pvwAppVersion = (IpvwAppVersion)this.m_pvwServer;
            }
            catch (COMException)
            {
                //provision does not exists or contains error
                return false;
            }
          

            return true;
        }

        public bool SubmitCIFRequest(string strFile)
        {
            string pstrRequestFile = strFile;
            this.m_pvwAppCIF.CIFRequestFile(ref pstrRequestFile);
            return true;
        }

        // Properties
        public string PvwPath
        {
            get
            {
                return this.m_pvwAppFileManagement.RunPath;
            }
        }
    }
}
